package com.tbq.tbqj_ggl.activity

import android.view.View
import android.widget.TextView
import com.tbq.sdk.L
import com.tbq.sdk.TBQ
import com.tbq.tbqj_ggl.R
import com.tbq.tbqj_ggl.model.Prizes
import com.tbq.tbqj_ggl.view.ScratchImageView
import pw.hais.http.Http

/**
 * 一卦千金
 * Created by hais1992 on 2017/5/11.
 */

class ScratchYGQJGameActivity : ScrachGameBaseActivity(if (TBQ.get("KEY_IS_MOBILE") == "1") R.layout.mobile_scratch_ygqj_game else
    R.layout.activity_scratch_ygqj_game), ScratchImageView.OnScratchListent, View.OnClickListener {
    override fun onScratchItem(view: ScratchImageView?) {
        findViewById(R.id.text_start).setBackgroundDrawable(resources.getDrawable(R.drawable.scratch_game_btzlyc))
    }

    override fun onClick(p0: View?) {
        if (scratch_prize?.isScratch!!) {
            scratch_prize?.setComplete(true)
        } else {
            L.showShort("要先刮动涂层才可以直接 兑奖 哟！")
        }
    }

    private var isWin: Boolean = false
    private var scratch_prize: ScratchImageView? = null

    override fun initDataAndView() {
        scratch_prize = findViewById(R.id.scratch_prize) as ScratchImageView
        scratch_prize!!.setOnScratchListent(this)
        (findViewById(R.id.text_message) as TextView).text = "1.刮奖可以选择多种面额,面额越大奖品越丰富。\n" +
                "2.刮开覆盖层，如果刮奖区任意一个\"奖品\"与开奖区相同，即可获得开奖区奖品。\n" +
                "刮奖区其他的\"奖品\"与开奖区不同的\"奖品\"无效。\n" +
                "3.中奖后选择领取奖品方式。\n" +
                "4.\"再来一次\"即放弃本局刮奖,并消耗相应面额金币进行下一轮刮奖。"

        findViewById(R.id.text_start).setOnClickListener(this)
    }


    override fun initDataToStartGame(challengePrize: Prizes, isWin: Boolean) {
        super.initDataToStartGame(challengePrize, isWin)

        this.isWin = isWin
        scratch_prize!!.resteData()
        if (isWin) {
            Http.displayImageAutoSize(scratch_prize, SERVER_URL + challengePrize.Icon)
        } else {
            scratch_prize!!.setImageResource(R.drawable.scratch_ygqj_xxhg)
        }
    }


    override fun onScratchFull(view: ScratchImageView) {
        if (!isPlayGameing) return
        showGameResultWindows(isWin)
        findViewById(R.id.text_start).setBackgroundDrawable(resources.getDrawable(R.drawable.scratch_game_btzlyc_hs))
    }
}
